package cn.com.callback;

import cn.com.elite.Util;
import cn.com.kh.KHDBConfig
import cn.com.kh.KHUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.com.elite.EliteBean;
import org.springframework.jdbc.core.JdbcTemplate;

// 系统定时执行SQL

public class autoQWDataInit implements CallBackInvoke {
    private static final Logger log = LoggerFactory.getLogger(autoQWDataInit.class);

    public void doCallBack(EliteBean eliteBean, String callBack, Map map, String paramString) {
        long astartTime = System.currentTimeMillis();
        log.debug("系统定时执行SQL-开始:" + astartTime);
        String autoSQL = '''Select Rec_Guid,
                                   Operation1,
                                   Operation1type,
                                   Operation2,
                                   Operation2type,
                                   Extra,
                                   Seq,
                                   Startindex,
                                   Endindex,
                                   Datasource,
                                   Comments
                              From Autodatasummaryconfig
                             Where Taskname = 'TaskAutoRun\'
                             Order By Seq''';
        List<Map<String, Object>> autoSQLList = eliteBean.chaxun_sql(autoSQL, "dataSource");
        log.debug("系统定时执行SQL-待执行SQL数量:" + autoSQLList.size() + " 详情List:" + autoSQLList);

        for (int i = 0; i < autoSQLList.size(); i++) {
            long startTime = System.currentTimeMillis();
            String Rec_Guid = autoSQLList.get(i).get("Rec_Guid").toString();
            String Operation1 = autoSQLList.get(i).get("Operation1").toString();
            String Datasource = autoSQLList.get(i).get("Datasource").toString();
            String Comments = autoSQLList.get(i).get("Comments").toString();
            Datasource = KHUtil.isNull(Datasource) ? "dataSource" : Datasource;
            log.debug("系统定制执行SQL-Rec_Guid:" + Rec_Guid + " Operation1:" + Operation1 + " Datasource:" + Datasource + " Comments:" + Comments);
            int deleteSQLRes = eliteBean.update(Operation1, Datasource);
            log.debug("系统定制执行SQL-执行结果:" + deleteSQLRes + " 耗时(毫秒):" + (System.currentTimeMillis() - startTime));
        }
        log.debug("系统定时执行SQL-结束" + " 耗时(毫秒):" + (System.currentTimeMillis() - astartTime));

    }

}